import { _decorator, Component, director, Node } from 'cc';
import { tt } from './Global';

const { ccclass, property } = _decorator;

@ccclass('TickTalk')
export class TickTalk{
    public static showBannerAd() {
        return new Promise<void>((resolve, reject) => {
            if(tt){
                console.log('激励视频广告准备中...');
                if(true){
                    let videoAd = tt.createRewardedVideoAd({
                        adUnitId: "4dc1h01knl962m4q0c",
                        multiton: true,
                        multitonRewardMsg: ['更多奖励1', '更多奖励2', '更多奖励3'],
                        multitonRewardTimes: 3,
                        progressTip: false,
                    });
                    videoAd.show().then(() => {
                        console.log("视频广告展示");
                    });
                    
                    videoAd.onClose(res => {
                        // 用户点击了【关闭广告】按钮
                        // 小于 2.1.0 的基础库版本，res 是一个 undefined
                        if (res && res.isEnded || res === undefined) {
                            // 正常播放结束，可以下发游戏奖励的逻辑
                            console.log(`watch ${res.count} video`);
                            //director.resume();
                            //todo：插屏广告等待播放的计时恢复...
 
                            resolve();  
                        }
                        else {
                            // 播放中途退出，不下发游戏奖励
                            director.resume();
                            //todo：插屏广告等待播放的计时恢复...
 
                            reject();
                        }
                    });
                }  
            }else{
                //todo：插屏广告等待播放的计时恢复...
 
                resolve();
            }
        })
        // Implementation for showing a banner ad
    }

    public static showInterstitialAd() {
        // Implementation for showing an interstitial ad
    }

    public static showRewardedAd() {
        // Implementation for showing a rewarded ad
    }

    public static hideBannerAd() {
        // Implementation for hiding a banner ad
    }


       //激励视频实现：
    static playVideo(num ?: number){
        
    }
}


